<template>
	<view class="pagebody" style="padding-bottom: 10px;">
		<view class="app-top-search">
			<uni-search-bar placeholder="请输入关键字" @input="search"></uni-search-bar>
		</view>
		<view class="bg-white p10 app-category-box" v-for="c in categoryList">
			<div class="app-category-title-box">{{c.categoryTitle}}</div>
			<div :key="index" v-for="(item,index) in rows" class="app-item-box" v-if="c.appCategoryID==item.appCategoryID"
				@click="openWorkflowfrom(item.appId,item.title)">
				<div class="app-item-circle-box app-item-bg-color1 mt10 mr3">
					<span @click.stop="showWorkflowMap(item.appId,item.workflowId) "><i
							class="fa fa-file-image-o app-item-fa" title="点击查看流程图"></i></span>
				</div>
				<div class="square_box">
					<view><span class="app-item-title">{{item.title}} </span></view>
				</div>
			</div>
		</view>

		 
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	export default {
		components: {
			uniSearchBar
		},
		onLoad: function(option) {
			var that = this;
			var success = that.$store.getters.validateLogin;
			if (!success) {
				FUI.Window.showMsg("您未登录")
				return false;
			}
			that.isHaveLogin = true;
		},
		onPullDownRefresh: function() {
			//下拉刷新
			var that = this;
			if (that.isHaveLogin) {
				that.loadList(1);
			}
			uni.stopPullDownRefresh();
		},
		data() {
			return {
				isHaveLogin: false,
				searchParams: {
					searchkey: ''
				},
				categoryList: [],
				rows: [],
				temData: []
			}
		},
		computed: {
			...mapState(['author'])
		},
		created() {
			var that = this;
			if (that.isHaveLogin) {
				that.loadList(1);
			}

		},
		methods: {
			openWorkflowfromView: function(row) {
				var appId = row.appId;
				var formAction = 2;
				var wiid = row.workflowInstanceId;
				var taskId = row.taskId;
				var title = row.workflowTitle;
				console.info(appId)
			},
			search(v) {
				var that = this;
				that.searchParams.searchkey = v.value;
				if (v) {
					that.rows = that.temData.filter(a => a.appId.toLocaleLowerCase().indexOf(that.searchParams.searchkey
							.toLocaleLowerCase()) > -1 || a.title
						.indexOf(that.searchParams.searchkey) > -1);
				} else {
					that.rows = that.temData;
				}
				that.loadCategoryList();
			},
			loadList() {
				var that = this;
				var parms = that.searchParams;
				parms.isMobile = 1;
				var res = that.$myObject.toAjaxJson("/workflow/workflowBusiness/", "getStartWorkflowListJson", parms,
					function(res) {
						that.rows = res.data;
						that.temData = res.data;
						that.loadCategoryList();
					});
			},
			loadCategoryList() {
				var that = this;
				$.each(that.rows, function(i,item) {
					var one = that.categoryList.find(a => a.appCategoryID==item.appCategoryID);
					if (one == null) {
						that.categoryList.push({
							categoryTitle: item.categoryTitle,
							appCategoryID: item.appCategoryID
						});
					}
				})
			},
			showWorkflowMap(appId, wid) {
				var tourl = __webpath + "/workflow/businessMP/workflowMap?wid=" + wid;
				FUI.Window.openEdit(tourl, "查看【" + appId + "】流程图", "View", null, null, null, null, null, null, true);
			},
			openWorkflowfrom(appId, title) {
				var url = __webpath + "/workflow/businessMP/workflowform?appId=" + appId;
				FUI.Window.ngto(url);
				//FUI.Window.open(url, '_blank')
				//FUI.Window.openEdit(url, title, null, null, null, null, null, null, null, true);
			}
		}
	}
</script>

<style>
	@import url("@/static/css/startWorkflowList.css");
</style>
